<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/7/20
  Time: 16:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>

<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" id="email" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码框</label>
        <div class="layui-input-inline">
            <input type="password" id="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit lay-filter="login111">登录</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        form.on('submit(login111)', function(data){
            console.log(data)
            layui.jquery.ajax({
                url:"${pageContext.request.contextPath}/admin/login",
                type:"post",
                contentType:"application/json",
                data:JSON.stringify(data.field),
                success:function (ret) {
                    if(ret == "success"){
                        alert("登录成功！");
                        setTimeout(function () {


                            location.href="${pageContext.request.contextPath}/index.jsp"
                        },1000)
                    }else if(ret == "false"){
                        alert("密码错误！");
                        setTimeout(function () {
                            location.href="${pageContext.request.contextPath}/login.jsp"
                        },1000)
                    }else if(ret == "err"){
                        alert("用户不存在！");
                        setTimeout(function () {
                            location.href="${pageContext.request.contextPath}/login.jsp"
                        },1000)
                    }else {
                        alert("未知错误");
                        setTimeout(function () {
                            location.href="${pageContext.request.contextPath}/login.jsp"
                        },1000)
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
